﻿namespace USSDRunner
{
    using System.Windows;

    /// <summary>
    /// Represents user control, which displays application and page titles.
    /// </summary>
    public partial class TitleControl
    {
        /// <summary>
        /// The page title dependency property.
        /// </summary>
        public static readonly DependencyProperty PageTitleProperty = DependencyProperty.Register(
            "PageTitle",
            typeof(string),
            typeof(TitleControl),
            new PropertyMetadata(string.Empty, HandleTitleChanged));

        /// <summary>
        /// Initializes a new instance of the <see cref="TitleControl"/> class.
        /// </summary>
        public TitleControl()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Gets or sets the page title.
        /// </summary>
        /// <value>
        /// The page title.
        /// </value>
        public string PageTitle
        {
            get { return (string)GetValue(PageTitleProperty); }
            set { SetValue(PageTitleProperty, value); }
        }

        private static void HandleTitleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var titleControlObject = (TitleControl)d;
            var newValue = (string)e.NewValue;
            titleControlObject.PageTitleTextBlock.Text = newValue;
        }
    }
}
